package com.pgybook.db.entity.mapper;

import org.springframework.stereotype.Repository;
import com.pgybook.db.entity.domain.Role;
import com.pgybook.db.entity.domain.RoleEx;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Repository
public interface RoleMapper {
    int countByExample(RoleEx example);

    int deleteByExample(RoleEx example);

    @Delete({
            "delete from role",
            "where ID = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
            "insert into role (NAME, DESCRIPTION, ",
            "CRTTIME, UPTTIME, ",
            "CRTSTAFF, UPTSTAFF)",
            "values (#{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, ",
            "#{crttime,jdbcType=TIMESTAMP}, #{upttime,jdbcType=TIMESTAMP}, ",
            "#{crtstaff,jdbcType=INTEGER}, #{uptstaff,jdbcType=INTEGER})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insert(Role record);

    int insertSelective(Role record);

    List<Role> selectByExample(RoleEx example);

    @Select({
            "select",
            "ID, NAME, DESCRIPTION, CRTTIME, UPTTIME, CRTSTAFF, UPTSTAFF",
            "from role",
            "where ID = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    Role selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") Role record, @Param("example") RoleEx example);

    int updateByExample(@Param("record") Role record, @Param("example") RoleEx example);

    int updateByPrimaryKeySelective(Role record);

    @Update({
            "update role",
            "set NAME = #{name,jdbcType=VARCHAR},",
            "DESCRIPTION = #{description,jdbcType=VARCHAR},",
            "CRTTIME = #{crttime,jdbcType=TIMESTAMP},",
            "UPTTIME = #{upttime,jdbcType=TIMESTAMP},",
            "CRTSTAFF = #{crtstaff,jdbcType=INTEGER},",
            "UPTSTAFF = #{uptstaff,jdbcType=INTEGER}",
            "where ID = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Role record);
}
